﻿using IceZero.Business;
using IceZero.DataStore.Models;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IceZero.Web.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ShortLinkController : ControllerBase
    {
        private ShortLinkBusiness _shortLinkBusiness;

        public ShortLinkController(ShortLinkBusiness shortLinkBusiness)
        {
            _shortLinkBusiness = shortLinkBusiness;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        /// <summary>
        /// 创建短链接
        /// </summary>
        /// <param name="rawUrl">原始链接</param>
        /// <param name="effectSeconds">有效秒数，默认600秒(60-604800[7天])</param>
        /// <returns></returns>
        [HttpGet]
        public ShortLink CreateShortLink(string rawUrl, int effectSeconds = 60)
        {
            return _shortLinkBusiness.CreateShortLink(rawUrl, effectSeconds);
        }

        /// <summary>
        /// 通过 id 获取短连接
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ShortLink GetShortLinkInfoById(string id)
        {
            return _shortLinkBusiness.GetShortLinkInfoById(id);
        }

        /// <summary>
        /// 通过 code 获取短连接
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        public ShortLink GetShortLinkInfoByCode(string code)
        {
            return _shortLinkBusiness.GetShortLinkInfoByCode(code);
        }
    }
}
